package com.netsdk.demo.module;

import com.netsdk.lib.ToolKits;
import com.netsdk.lib.NetSDKLib.fMessCallBack;

/**
 * 报警接口实现
 * 主要有 ：订阅、取消订阅、设置订阅回调
 */
public class AlarmListenModule {

	private static boolean bListening = false;

	
	/**
	 * 订阅
	 */
	public static boolean startListen(fMessCallBack cbMessage) {

		if (bListening) {
//			System.out.println("Had Subscribe Alarm.");
			return true;
		}
		
		LoginModule.netsdk.CLIENT_SetDVRMessCallBack(cbMessage, null); // 设置报警回调函数

		if (!LoginModule.netsdk.CLIENT_StartListenEx(LoginModule.m_hLoginHandle)) { // 订阅报警
			System.err.printf("CLIENT_StartListenEx Failed!" + ToolKits.getErrorCodePrint());
			return false;
		} else { 
			System.out.println("CLIENT_StartListenEx success."); 
		}
		
		bListening = true;
		return true;
	}
	
	/**
	 * 取消订阅
	 */
	public static boolean stopListen() {

		if (!bListening) {
			return true;
		}
		
	   	if (!LoginModule.netsdk.CLIENT_StopListen(LoginModule.m_hLoginHandle)) { 
			System.err.printf("CLIENT_StopListen Failed!" + ToolKits.getErrorCodePrint());
			return false;
		} else { 
			System.out.println("CLIENT_StopListen success."); 
		}
	   	
	   	bListening = false;	
		return true;
	}

}	
	



